package com.lianniu.mgr.product.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.lianniu.mgr.util.StringUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.constants.ErrorCode;
import com.lianniu.mgr.pagination.PaginationInfo;
import com.lianniu.mgr.product.model.ProductCateVo;
import com.lianniu.mgr.product.model.ProductPicVo;
import com.lianniu.mgr.product.model.ProductSpecRelVo;
import com.lianniu.mgr.product.model.ProductSpecValueVo;
import com.lianniu.mgr.product.model.ProductVo;
import com.lianniu.mgr.product.service.IProductCateService;
import com.lianniu.mgr.product.service.IProductModelService;
import com.lianniu.mgr.product.service.IProductService;
import com.lianniu.mgr.product.service.IProductSpecRelService;
import com.lianniu.mgr.product.service.IProductSpecService;
import com.lianniu.mgr.product.service.IProductSpecValueService;

@Controller
@RequestMapping("/rest/product")
public class ProductRestController {
	
	private static final Logger logger = Logger.getLogger(ProductRestController.class);

	
	 @Autowired
	  private IProductService productService;
	 @Autowired
	 private IProductSpecService psService;
	 @Autowired
	 private IProductSpecRelService psrService;
	 @Autowired
	 private IProductCateService cateService;
	 @Autowired
	 private IProductSpecValueService specValueService;
	
	  /**
	   * 
	   * @Title: ProductList 
	   * @Description: 商品列表
	   * @author: guoconglin
	   * @param request
	   * @param pVo
	   * @param paginationInfo
	   * @return
	   * @date: 2016年7月14日 下午2:06:58 
	   * @return: BaseResult
	   */
	  @RequestMapping(value="/ProductList",method={RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult ProductList(HttpServletRequest request, ProductVo pVo, PaginationInfo paginationInfo)
	  {
	       logger.info("ProductRestController  ProductList begin.");
	       try {
	           
	           logger.info("ProductList begin.");          
	           BaseResult baseResult = productService.getProductsByProductNameForPage(pVo, paginationInfo);
	           logger.info(JSON.toJSONString(baseResult));
	           logger.info("ProductList end.");
	           logger.info("ProductRestController ProductList end.");
	           return baseResult;
	       } catch (Exception e) {
	       logger.error("ProductRestController ProductList error:" + e.getMessage());
	       logger.error("ProductRestController ProductList end.");
	       return BaseResult.exception(e.getMessage());
	     }
	  }
	  /**
	   * 
	   * @Title: ProductAdd 
	   * @Description: 添加商品
	   * @author: guoconglin
	   * @param request
	   * @param pVo
	   * @return
	   * @date: 2016年7月14日 下午2:07:31 
	   * @return: BaseResult
	   */
	  @RequestMapping(value = {"/ProductAdd"}, method = RequestMethod.POST)
	  public @ResponseBody BaseResult ProductAdd(HttpServletRequest request,ProductVo pVo) {
		  String cateId = request.getParameter("productModelName");
		  //pVo.setCateId("3");
	      logger.info("ProductRestController ProductAdd begin.");      
	      logger.info("ProductRestController ProductAdd:"+ JSON.toJSONString(pVo));
	      try {
	          logger.info("ProductAdd begin.");
	          String picId = request.getParameter("picId");
	          pVo.setPicId(picId);
	          String[] specValueId = request.getParameterMap().get("specValueId");
	          String[] specValueName = request.getParameterValues("specValueName");
			  String[] specId = request.getParameterValues("specId");
	          String addUser = request.getParameter("addUser");
	          String priceRetailGuideStr = request.getParameter("priceRetailGuide");
	          String teaDeTime = request.getParameter("teaDeTime");
	          String freightStr = request.getParameter("freight");
	          double freight = Double.parseDouble(freightStr);
	          pVo.setFreight(freight);
	          if (StringUtil.isEmpty(teaDeTime)) {
				pVo.setTeaDeTime(null);
	          }
	          double priceRetailGuide = Double.parseDouble(priceRetailGuideStr);
	          pVo.setPriceRetailGuide(priceRetailGuide);
	          pVo.setAddUser("0");
	          BaseResult baseResult = productService.addProduct(pVo);
	          //BaseResult base = productService.selectByLastId();
	          //String productId = base.getData().toString();
	          String productId = pVo.getProductId();
	          ProductSpecRelVo psrVo = new ProductSpecRelVo();
	          ProductSpecValueVo psvVo = new ProductSpecValueVo();
	          if(specValueId != null&&specValueId.length>0){
		         for(int i=0;i<specValueId.length;i++){
		        	psrVo.setProductId(productId);
		        	psrVo.setSpecValueId(specValueId[i]); 
		        	psrVo.setAddUser(addUser);
		        	psrVo.setDelFlag("1");
		        	psrService.insert(psrVo);
		        }
	          }else{
	              psrVo.setProductId(productId);
                  psrVo.setSpecValueId(""); 
                  psrVo.setAddUser(addUser);
                  psrVo.setDelFlag("1");
                  psrService.insert(psrVo);
	          }
			  if(specValueName == null || specValueName.length == 0){
			      psvVo.setSpecValueName("");
                  psvVo.setAddUser(addUser);
				  psvVo.setSpecId(specId[0]);
                  psvVo.setDelFlag("1");
                  specValueService.insertProductSpecValue(psvVo);
                  String valueId = psvVo.getSpecValueId();
                  psrVo.setProductId(productId);
                  psrVo.setSpecValueId(valueId);
                  psrVo.setAddUser(addUser);
                  psrVo.setDelFlag("1");
                  psrService.insert(psrVo);   
			          
		     }else{
		         for(int j=0;j<specValueName.length;j++){
                     psvVo.setSpecValueName(specValueName[j]);
					 psvVo.setSpecId(specId[j]);
                     psvVo.setAddUser(addUser);
                     psvVo.setDelFlag("1");
                     specValueService.insertProductSpecValue(psvVo);
                     //String valueId = specValueService.selectByLastId().getData().toString();
                     String valueId = psvVo.getSpecValueId();
                     psrVo.setProductId(productId);
                     psrVo.setSpecValueId(valueId);
                     psrVo.setAddUser(addUser);
                     psrVo.setDelFlag("1");
                     psrService.insert(psrVo);   
                 }      	
		   }
	          logger.info("ProductAdd baseResult:" + JSON.toJSONString(baseResult));
	          logger.info("ProductAdd end.");
	          return BaseResult.success(baseResult);
	    } catch (Exception e) {
	      logger.error("ProductAdd error:"+e.getMessage());
	      logger.info("ProductRestController ProductAdd end.");
	      return BaseResult.exception(e.getMessage());
	    }

	  } 
	  
	 /**
	  * 
	  * @Title: ProductEdit 
	  * @Description: 编辑商品
	  * @author: guoconglin
	  * @param request
	  * @param pVo
	  * @return
	  * @date: 2016年7月14日 下午2:08:12 
	  * @return: BaseResult
	  */
	  @RequestMapping(value = {"/ProductEdit"}, method = RequestMethod.POST)
	  public @ResponseBody BaseResult ProductEdit(HttpServletRequest request,ProductVo pVo) {
	      logger.info("ProductRestController ProductEdit begin.");      
	      logger.info("ProductRestController ProductEdit:"+ JSON.toJSONString(pVo));
	      try {
	          logger.info("ProductEdit begin.");
	          String picId = request.getParameter("picId");
              pVo.setPicId(picId);
	          BaseResult baseResult = productService.updateById(pVo);
	          String[] specValueId = request.getParameterMap().get("specValueId");
	          String[] specValueName = request.getParameterValues("specValueName");
			  String[] specId = request.getParameterValues("specId");
              String[] curSpecValueId = request.getParameterValues("curSpecValueId");
	          String addUser = request.getParameter("addUser");
	          String productId = pVo.getProductId();
	          ProductSpecRelVo psrVo = new ProductSpecRelVo();
	          ProductSpecValueVo psvVo = new ProductSpecValueVo();
	          psrVo.setProductId(productId);
	          psrService.deleteById(productId);
	          if(specValueId != null&&specValueId.length>0 ){
			         for(int i=0;i<specValueId.length;i++){
			        	psrVo.setProductId(productId);
			        	psrVo.setSpecValueId(specValueId[i]); 
			        	psrVo.setAddUser(addUser);
			        	psrVo.setDelFlag("1");
			        	psrService.insert(psrVo);
			        }
		          }
			  //插入手输入值默认进来有值
			  if(specValueName == null || specValueName.length==0) {
				  if(curSpecValueId== null || curSpecValueId.length==0){
				  }
				  else
				  {
					  for(int i=0;i<curSpecValueId.length;i++)  {
						  if(curSpecValueId[i]==null||curSpecValueId[i].equals("null")||curSpecValueId[i].equals("")||curSpecValueId[i].length()==0){ continue;}
						  else{
							  psvVo.setSpecValueName("");
							  psvVo.setSpecId(specId[i]);
							  psvVo.setAddUser(addUser);
							  psvVo.setDelFlag("1");
							  psvVo.setSpecValueId(curSpecValueId[i]);
							  //插入关系之前都删了
							  psrVo.setProductId(productId);
							  psrVo.setSpecValueId(curSpecValueId[i]);
							  psrVo.setAddUser(addUser);
							  psrVo.setDelFlag("1");
							  psrService.insert(psrVo);
							  specValueService.updateBySpecValueId(psvVo);
						  }
					  }
				  }
			  }
			  else {
					  for(int j=0;j<specValueName.length;j++) {
						  if(specValueName[j]==null||specValueName[j].equals("null")||specValueName[j].equals("")||specValueName[j].length()==0)
						  {
								  if(curSpecValueId[j]==null||curSpecValueId[j].equals("null")||curSpecValueId[j].equals("")||curSpecValueId[j].length()==0){ }
								  else{
										  psvVo.setSpecValueName("");
										  psvVo.setSpecId(specId[j]);
										  psvVo.setAddUser(addUser);
										  psvVo.setDelFlag("1");
										  psvVo.setSpecValueId(curSpecValueId[j]);
										  //插入关系之前都删了
										  psrVo.setProductId(productId);
										  psrVo.setSpecValueId(curSpecValueId[j]);
										  psrVo.setAddUser(addUser);
										  psrVo.setDelFlag("1");
										  psrService.insert(psrVo);
										  specValueService.updateBySpecValueId(psvVo);
								       }
						  }
						  else {
							  psvVo.setSpecValueName(specValueName[j]);
							  psvVo.setSpecId(specId[j]);
							  psvVo.setAddUser(addUser);
							  psvVo.setDelFlag("1");
							  if(curSpecValueId[j]==null||curSpecValueId[j].equals("null")||curSpecValueId[j].equals("")||curSpecValueId[j].length()==0){
								  specValueService.insertProductSpecValue(psvVo);
								  String valueId = psvVo.getSpecValueId();
								  psrVo.setProductId(productId);
								  psrVo.setSpecValueId(valueId);
								  psrVo.setAddUser(addUser);
								  psrVo.setDelFlag("1");
								  psrService.insert(psrVo);
							  }
							  else {
								  psvVo.setSpecValueId(curSpecValueId[j]);
								  specValueService.updateBySpecValueId(psvVo);
							  }
						  }
					  }
		           }
	          logger.info("ProductEdit baseResult:" + JSON.toJSONString(baseResult));
	          logger.info("ProductEdit end.");
	          return baseResult;

	    } catch (Exception e) {
	      logger.error("ProductEdit error:"+e.getMessage());
	      logger.info("ProductRestController ProductEdit end.");
	      return BaseResult.exception(e.getMessage());
	    }
	  }  
	  
	  /**
	   * 
	   * @Title: selectProductById 
	   * @Description: 获取商品信息
	   * @author: guoconglin
	   * @param request
	   * @param pVo
	   * @return
	   * @date: 2016年7月14日 下午2:08:42 
	   * @return: BaseResult
	   */
	  @SuppressWarnings("unchecked")
	  @RequestMapping(value="/selectProductById",method={RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult selectProductById(HttpServletRequest request,ProductVo pVo) {
	        logger.info("ProductRestController selectProductById begin.");
	        try {            
	          BaseResult baseResult = productService.selectByProductId(pVo);
	          ProductVo productVo = (ProductVo)baseResult.getData();
	          List<ProductCateVo> cateParentNames = (List<ProductCateVo>)cateService.getByParentId("0").getData();
	          List<ProductCateVo> cateChildNames = (List<ProductCateVo>)cateService.getByParentId(productVo.getCateChildNameId()).getData();
	          List<ProductCateVo> brandParentNames = (List<ProductCateVo>)cateService.getByParentId(productVo.getBrandParentNameId()).getData();
	          List<ProductCateVo> brandChildNames = (List<ProductCateVo>)cateService.getByParentId(productVo.getBrandChildNameId()).getData();
	          List<ProductCateVo> cateNames = (List<ProductCateVo>)cateService.getByParentId(productVo.getCateNameId()).getData();
	          Map<String,Object> map = new HashMap<String,Object>();
	          map.put("cateParentNames", cateParentNames);
	          map.put("cateChildNames", cateChildNames);
	          map.put("brandParentNames", brandParentNames);
	          map.put("brandChildNames", brandChildNames);
	          map.put("cateNames", cateNames);
	          map.put("productVo", productVo);
	          logger.info("selectDictionaryById end.");
	          logger.info("ProductRestController selectProductById end.");
	          return BaseResult.success(map);
	        } catch (Exception e) {
	          logger.error("ProductRestController selectProductById error:" + e.getMessage());
	          logger.error("ProductRestController selectProductById end.");
	          return BaseResult.exception(e.getMessage());
	        }
	  }
	  /**
	   * 
	   * @Title: checkProductName 
	   * @Description: 校验商品
	   * @author: guoconglin
	   * @param request
	   * @return
	   * @date: 2016年7月14日 下午2:09:04 
	   * @return: Boolean
	   */
	  @RequestMapping(value = {"/checkProductName"}, method = RequestMethod.POST)
	  public @ResponseBody Boolean checkProductName(HttpServletRequest request) {
	      Boolean flag=true;
	      String productName=  request.getParameter("productName");
	      logger.info("ProductRestController checkProductName begin.");
	     try {          
	          logger.info("checkProductName begin.");
	          if("".equalsIgnoreCase(productName)||productName==null)
	          {return flag;}
	          flag = productService.checkProductName(productName);         
	          logger.info("checkProductName end.");
	          logger.info("ProductRestController checkProductName end.");
	          return flag;
	    } catch (Exception e) {
	      logger.error("ProductRestController checkProductName error:" + e.getMessage());
	      logger.info("ProductRestController checkProductName end.");
	      return flag;
	    }

	  }
	  /**
	   * 
	   * @Title: ProductDel 
	   * @Description: 批量删除商品
	   * @author: guoconglin
	   * @param request
	   * @return
	   * @date: 2016年7月14日 下午2:09:49 
	   * @return: BaseResult
	   */
	  @RequestMapping(value = {"/ProductDel"}, method = RequestMethod.POST)
	  public @ResponseBody BaseResult ProductDel(HttpServletRequest request) {
	      logger.info("ProductRestController ProductDel begin.");
	     try {          
	          logger.info("ProductBrandDel begin.");
	          BaseResult baseResult = productService.deleteProductBatch(request.getParameter("ids").split(","));		
	          logger.info("ProductDel baseResult:" + JSON.toJSONString(baseResult));
	          logger.info("ProductDel end.");
	          
	          logger.info("ProductRestController ProductDel end.");
	          return baseResult;

	    } catch (Exception e) {
	      logger.error("ProductRestController ProductDel error:" + e.getMessage());
	      logger.info("ProductRestController ProductDel end.");
	      return BaseResult.exception(e.getMessage());
	    }

	  }
	  /**
	   * 
	   * @Title: checkProductNameEdit 
	   * @Description: TODO
	   * @author: guoconglin
	   * @param request
	   * @return
	   * @date: 2016年7月14日 下午2:10:26 
	   * @return: Boolean
	   */
	  @RequestMapping(value = {"/checkProductNameEdit"}, method = RequestMethod.POST)
	  public @ResponseBody Boolean checkProductNameEdit(HttpServletRequest request) {
	      Boolean flag=true;
	      String productName=  request.getParameter("productName");
	      String productId=request.getParameter("productId");
	      logger.info("ProductRestController checkProductNameEdit begin.");
	     try {          
	          logger.info("checkProductNameEdit begin.");
	          ProductVo vo=new ProductVo();	         
	          vo.setProductId(productId);  
	          BaseResult baseResult =productService.selectByProductId(vo);          
	          ProductVo pVo=(ProductVo) baseResult.getData();
	          if(pVo.getProductId().equals(productId)&&pVo.getProductName().equals(productName))
	          {return flag;}
	          if("".equalsIgnoreCase(productName)||productName==null)
	          {return flag;}
	          flag = productService.checkProductName(productName);         
	          logger.info("checkProductNameEdit end.");
	          
	          logger.info("ProductRestController checkProductNameEdit end.");
	          return flag;
	    } catch (Exception e) {
	      logger.error("ProductPicRestController checkPicNameEdit error:" + e.getMessage());
	      logger.info("ProductPicRestController checkPicNameEdit end.");
	      return flag;
	    }

	  }
	  /**
	   * 
	   * @Title: selectByCateId 
	   * @Description:通过二级分类查找属性
	   * @author: alex
	   * @param request
	   * @param psVo
	   * @return
	   * @date: 2016年11月14日 下午2:10:42 
	   * @return: BaseResult
	   */
	  @RequestMapping(value="/selectByCateId",method={RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult selectByCateId(HttpServletRequest request,ProductCateVo psVo) {
	        logger.info("ProductSpecRestController selectByCateId begin.");	        
	        logger.info("ProductSpecRestController selectByCateId cateId:" + JSON.toJSONString(psVo.getCateId()));
	        try {	                    
	          BaseResult baseResult = psService.selectByCateId(psVo.getCateId());
	          logger.info("selectByCateId end.");
	          logger.info("ProductSpecRestController selectByCateId end.");
			  logger.info("ProductSpecRestController selectByCateId baseResult:" + JSON.toJSONString(baseResult));
	          return baseResult;
	        } catch (Exception e) {
	          logger.error("ProductSpecRestController selectByCateId error:" + e.getMessage());
	          logger.error("ProductSpecRestController selectByCateId end.");
	          return BaseResult.exception(e.getMessage());
	        }
	  }
	  /**
	   * 
	   * @Title: getProductNameByCateId 
	   * @Description: 查找二级分类下的商品
	   * @author: guoconglin
	   * @param request
	   * @param psVo
	   * @return
	   * @date: 2016年11月14日 下午2:19:25 
	   * @return: BaseResult
	   */
	  @RequestMapping(value = "/getProductNameByCateId",
	                    method = {RequestMethod.GET, RequestMethod.POST})
	    public @ResponseBody BaseResult getProductNameByCateId(HttpServletRequest request,
	                    ProductCateVo psVo) {
	        logger.info("SkuProductRestController getProductNameByCateId begin.");
	        logger.info("SkuProductRestController getProductNameByCateId cateId:"
	                        + JSON.toJSONString(psVo.getCateId()));
	        try {
	            BaseResult baseResult = cateService.selectByCateId(psVo.getCateId());
	            logger.info("getProductNameByCateId end.");
	            logger.info("SkuProductRestController getProductNameByCateId end.");
	            return baseResult;
	        } catch (Exception e) {
	            logger.error("SkuProductRestController getProductNameByCateId error:" + e.getMessage());
	            logger.error("SkuProductRestController getProductNameByCateId end.");
	            return BaseResult.exception(e.getMessage());
	        }
	    }
	  
	  /**
	   * 用户发布管理页面
	   * @param request
	   * @param pVo
	   * @param paginationInfo
	   * @return
	   */
	  @RequestMapping(value="/WeixinProductList",method={RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult WeixinProductList(HttpServletRequest request, ProductVo pVo, PaginationInfo paginationInfo)
	  {
	       logger.info("ProductRestController  ProductList begin.");
	       try {
	           
	           logger.info("ProductList begin.");          
	           BaseResult baseResult = productService.getWeixinProductsByProductNameForPage(pVo, paginationInfo);
	           logger.info(JSON.toJSONString(baseResult));
	           logger.info("ProductList end.");
	           logger.info("ProductRestController ProductList end.");
	           return baseResult;
	       } catch (Exception e) {
	       logger.error("ProductRestController ProductList error:" + e.getMessage());
	       logger.error("ProductRestController ProductList end.");
	       return BaseResult.exception(e.getMessage());
	     }
	  }
	  /**
	   * 管理人员是否通过用户的发布
	   */
	  @RequestMapping(value = {"/weixinproductEdit"}, method = {RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult weixinproductEdit(HttpServletRequest request,ProductVo pVo) {
	      logger.info("ProductRestController weixinproductEdit begin.");      
	      logger.info("ProductRestController weixinproductEdit:"+ JSON.toJSONString(pVo));
	      try {
	          logger.info("weixinproductEdit begin.");
	          String productId = request.getParameter("productId");
              pVo.setProductId(productId);
	          BaseResult baseResult = productService.weixinproductEdit(pVo);
	          return baseResult;
	    } catch (Exception e) {
	      logger.error("ProductEdit error:"+e.getMessage());
	      logger.info("ProductRestController weixinproductEdit end.");
	      return BaseResult.exception(e.getMessage());
	    }
	  }  
	  /**
	   * 拒绝用户的发布
	   * @param request
	   * @param pVo
	   * @return
	   */
	  @RequestMapping(value = {"/ProductEditre"}, method = {RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult ProductEditre(HttpServletRequest request,ProductVo pVo) {
		  logger.info("ProductRestController ProductEditre begin.");      
		  logger.info("ProductRestController ProductEditre:"+ JSON.toJSONString(pVo));
		  try {
			  logger.info("ProductEditre begin.");
			  String productId = request.getParameter("productId");
			  pVo.setProductId(productId);
			  BaseResult baseResult = productService.ProductEditre(pVo);
			  return baseResult;
		  } catch (Exception e) {
			  logger.error("ProductEdit error:"+e.getMessage());
			  logger.info("ProductRestController ProductEditre end.");
			  return BaseResult.exception(e.getMessage());
		  }
	  }  
	  @RequestMapping(value = {"/ProductEdittg"}, method = {RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult ProductEdittg(HttpServletRequest request,ProductVo pVo) {
		  logger.info("ProductRestController ProductEditre begin.");      
		  logger.info("ProductRestController ProductEditre:"+ JSON.toJSONString(pVo));
		  try {
			  logger.info("ProductEditre begin.");
			  String productId = request.getParameter("productId");
			  pVo.setProductId(productId);
			  BaseResult baseResult = productService.ProductEdittg(pVo);
			  return baseResult;
		  } catch (Exception e) {
			  logger.error("ProductEdit error:"+e.getMessage());
			  logger.info("ProductRestController ProductEditre end.");
			  return BaseResult.exception(e.getMessage());
		  }
	  }  
	  
	  @RequestMapping(value = {"/qxtsp"}, method = {RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult qxtsp(HttpServletRequest request,ProductVo pVo) {
		  logger.info("ProductRestController ProductEditre begin.");      
		  logger.info("ProductRestController ProductEditre:"+ JSON.toJSONString(pVo));
		  try {
			  logger.info("ProductEditre begin.");
			  String productId = request.getParameter("productId");
			  pVo.setProductId(productId);
			  BaseResult baseResult = productService.qxtsp(productId);
			  return baseResult;
		  } catch (Exception e) {
			  logger.error("ProductEdit error:"+e.getMessage());
			  logger.info("ProductRestController ProductEditre end.");
			  return BaseResult.exception(e.getMessage());
		  }
	  } 
	  
	  @RequestMapping(value = {"/count"}, method = {RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult count(HttpServletRequest request,ProductVo pVo) {
		  logger.info("ProductRestController ProductEditre begin.");      
		  logger.info("ProductRestController ProductEditre:"+ JSON.toJSONString(pVo));
		  try {
			  logger.info("ProductEditre begin.");
			  String productId = request.getParameter("productId");
			  pVo.setProductId(productId);
			  BaseResult baseResult = productService.count();
			  return baseResult;
		  } catch (Exception e) {
			  logger.error("ProductEdit error:"+e.getMessage());
			  logger.info("ProductRestController ProductEditre end.");
			  return BaseResult.exception(e.getMessage());
		  }
	  } 
	  
	  @RequestMapping(value = {"/totsp"}, method = {RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult totsp(HttpServletRequest request,ProductVo pVo) {
		  logger.info("ProductRestController ProductEditre begin.");      
		  logger.info("ProductRestController ProductEditre:"+ JSON.toJSONString(pVo));
		  try {
			  logger.info("ProductEditre begin.");
			  String productId = request.getParameter("productId");
			  pVo.setProductId(productId);
			  BaseResult baseResult = productService.totsp(pVo);
			  return baseResult;
		  } catch (Exception e) {
			  logger.error("ProductEdit error:"+e.getMessage());
			  logger.info("ProductRestController ProductEditre end.");
			  return BaseResult.exception(e.getMessage());
		  }
	  } 
	  
}
